class SingletonLazy{
    //懒汉模式就是第一次不创建实例，只有当调用getInstance方法时才创建实例
    //创建时机迟一点
    private static  volatile SingletonLazy instance=null;
    private static Object locker=new Object();
    public static SingletonLazy getInstance(){
        if(instance==null){
        synchronized(locker){
            if(instance==null){
                instance=new SingletonLazy();
            }
        }
    }
        return instance;
    }

}
public class Demo29 {
    public static void main(String[] args) {
        SingletonLazy s1=SingletonLazy.getInstance();
        SingletonLazy s2=SingletonLazy.getInstance();
        System.out.println(s1==s2);//true
    }
}
